#pragma once
#include "framework.h"

namespace poly
{
	class SInput : public IInput
	{
	public:
		// constructors
		SInput( HINSTANCE, HWND );
		~SInput();

		// import structs from IInput for ease of use
		using IInput::MOUSESTATE;
		using IInput::KEYSTATE;
		using IInput::JOYSTATE;

		// retrieve device states
		MOUSESTATE	mouseState();
		KEYSTATE	keyState();
		JOYSTATE	joyState( uint32 index );

		// early declaration
		class JoystickEnumerator;

		void enumJoysticks( JoystickEnumerator& );

		// abstract class for joystick enumeration
		class JoystickEnumerator
		{
		public:
			virtual bool handleJoystick(
				bool &create, // [out] return true to create joystick
				uint32 &cooperativeLevel, // [out]
				uint32 &objectEnumFlags, // [out] object enumeration flag,
				LPCDIDEVICEINSTANCE deviceInstance, // The physical device being enumerated
				uint32 joyIndex // [in] index of joystick being enumerated
				//return 0 to cancel object enumeration
				) = 0; // pure virtual function

			virtual bool handleJoystickObject(
				LPCDIDEVICEOBJECTINSTANCE objectInstance, DIDevice joystick, uint32 joyIndex ) = 0;
		};

	private:
		HWND		m_hWnd;
		HINSTANCE	m_hInstance;
		DInput		m_dinput;
		DIDevice	m_mouse;
		DIDevice	m_keyboard;
		std::vector<DIDevice> m_joysticks;

		static BOOL CALLBACK DIJoystickEnumDevCallback( LPCDIDEVICEINSTANCE deviceInstance, LPVOID pRef );
		static BOOL CALLBACK DIEnumDeviceObjectsCallback( LPCDIDEVICEOBJECTINSTANCE objectInstance, LPVOID pRef );
	};
}